//
//  YHMainTabBarViewController.swift
//  SniaWeiBo
//
//  Created by lcc on 16/5/11.
//  Copyright © 2016年 lcc. All rights reserved.
//

import UIKit

class YHMainTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let yhTabBar = YHTabBar()
        
        yhTabBar.composeButtonClousre = {[weak self] in
            
            print("点击了加号按钮");
            print(self)
            
            
        }
        
        //使用kvc设置只读属性
        setValue(yhTabBar, forKey: "tabBar")
        
        
        
        //调用方法
        addChildViewController(YHHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(YHMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        
        addChildViewController(YHDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(YHProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
        
    }

    func addChildViewController(childController: UIViewController,title: String ,imageName: String) {
        
        //设置全局统一的tabBar选中颜色
        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        //设置tabBar的title、image
        childController.tabBarItem.title = title
        childController.navigationItem.title = title
        
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")
        
        //修改文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(15)], forState: .Normal)
        
        //设置子视图控制器
        let navi = UINavigationController(rootViewController: childController)
        
        addChildViewController(navi)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
